/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Note: The returned array must be malloced, assume caller calls free().
  */
int treesize(struct TreeNode* root)
{
    if (root == NULL)
    {
        return 0;
    }
    return 1 + treesize(root->left) + treesize(root->right);
}
void postorder(struct TreeNode* root, int* arr, int* p)
{
    if (root == NULL)
    {
        return;
    }
    postorder(root->left, arr, p);
    postorder(root->right, arr, p);
    arr[(*p)++] = root->val;

}
int* postorderTraversal(struct TreeNode* root, int* returnSize) {
    *returnSize = treesize(root);
    int* arr = (int*)malloc(*returnSize * sizeof(int));
    int p = 0;
    postorder(root, arr, &p);
    return arr;
}